package com.zhiche.lisa.bms.service.trans.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zhiche.lisa.bms.dao.mapper.trans.TransTypeNameContrastMapper;
import com.zhiche.lisa.bms.dao.model.trans.TransTypeNameContrast;
import com.zhiche.lisa.bms.service.trans.TransTypeNameContrastService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 运输方式对照 服务实现类
 * </p>
 *
 * @author liuanshun
 * @since 2018-12-05
 */
@Service
public class TransTypeNameContrastServiceImpl extends ServiceImpl<TransTypeNameContrastMapper, TransTypeNameContrast> implements TransTypeNameContrastService {
    private EntityWrapper<TransTypeNameContrast> bindTransTypeNameEntityWrapper(Map<String, Object> condition) {
        EntityWrapper<TransTypeNameContrast> ew = new EntityWrapper<>();
        if(!CollectionUtils.isEmpty(condition)){
            for (Map.Entry<String,Object> item:
                 condition.entrySet()) {
                if(!StringUtils.isEmpty(item)){
                    if("id".equals(item.getKey())){ew.eq("id",item.getValue());}
                    if("transTypeName".equals(item.getKey())){ew.eq("trans_type_name",item.getValue());}
                }
            }
        }
        return ew;
    }


    @Override
    public List<TransTypeNameContrast> selectTransTypeNamesByTypeName(String typeName) {
        EntityWrapper<TransTypeNameContrast> ew = new EntityWrapper<>();
        ew.eq("trans_type_name", typeName);
        return this.selectList(ew);
    }

    @Override
    public List<TransTypeNameContrast> selectTransTypeNameList(Map<String, Object> condition) {
        EntityWrapper<TransTypeNameContrast> transTypeNameContrastEntityWrapper = bindTransTypeNameEntityWrapper(condition);
        return this.selectList(transTypeNameContrastEntityWrapper);
    }
}
